home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
objtools
/
spin.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
4KB
|
226 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* spin -
* View an sgi object interactively.
*
* Paul Haeberli - 1990
*/
#include "stdio.h"
#include "gl.h"
#include "device.h"
#include "sgiobj.h"
/*
* spin support follows
*
*/
float fgetmousex();
float fgetmousey();
float flerp();
sgiobj* obj;
int shownormals;
int showlines;
int showcolors;
int showmeshs;
int menu;
int envmap;
main(argc,argv)
int argc;
char **argv;
{
short val;
float zfactor;
if(argc<2) {
fprintf(stderr, "usage: spin object [environ.rgb]\n");
exit(1);
}
obj = readsgiobj(argv[1]);
if(!obj) {
fprintf(stderr, "spin: can't read %s\n",argv[1]);
exit(1);
}
zfactor = 5.0;
initwindow();
trackztrans(-3.0);
if(argc>=3) {
if(getgdesc(GD_TEXTURE)) {
textureread(argv[2],1);
envmap = 1;
} else {
fprintf(stderr, "spin: no texturing on this machine - oh well\n");
}
}
qmouse();
qdevice(ESCKEY);
qdevice(UPARROWKEY);
qdevice(DOWNARROWKEY);
while(1) {
while(qtest()) {
switch(qread(&val)) {
case ESCKEY:
exit(0);
break;
case LEFTMOUSE:
if(val) {
trackclick();
while(getbutton(LEFTMOUSE)) {
trackpoll();
drawit(obj);
}
}
break;
case MIDDLEMOUSE:
if(val) {
trackclick();
while(getbutton(MIDDLEMOUSE)) {
trackpoll();
drawit(obj);
}
}
break;
case MENUBUTTON:
if(val) {
switch(dopup(menu)) {
case 1:
shownormals = 1-shownormals;
break;
case 2:
showlines = 1-showlines;
break;
case 3:
showcolors = 1-showcolors;
break;
case 4:
savewindow("save.rgb");
printf("saved image to save.rgb\n");
break;
case 6:
showmeshs = 1-showmeshs;
break;
}
}
break;
case UPARROWKEY:
if(val) {
zfactor *= 1.41;
}
break;
case DOWNARROWKEY:
if(val) {
zfactor /= 1.41;
}
break;
}
}
drawit(obj);
}
}
initwindow()
{
keepaspect(5,4);
winopen("spin");
if(obj->objtype == OBJ_TRIMESH)
menu = defpup("spin %t|toggle normals|toggle lines|toggle color|save image|save lenticular|toggle showmeshs");
else
menu = defpup("spin %t|toggle normals|toggle lines|toggle color|save image|save lenticular");
matrixinit();
mygfxinit();
backface(0);
renderfperspective(25.0,5.0/4.0,0.3,20.0);
shadeinit();
}
clearback()
{
shadeoff();
zclear();
cpack(0x000000);
zbuffer(0);
clear();
}
drawit(obj)
sgiobj *obj;
{
reshapeviewport();
clearback();
pushmatrix();
tracktransform();
drawtheobj(obj);
popmatrix();
swapbuffers();
}
drawtheobj(obj)
sgiobj *obj;
{
srand(3);
if(showlines) {
zbuffer(0);
cpack(0x40ffffff);
drawsgiobj(obj,DRAW_LINES);
} else {
zbuffer(1);
if(envmap) {
cpack(0xffffff);
texgen(TX_S, TG_SPHEREMAP, 0);
texgen(TX_T, TG_SPHEREMAP, 0);
texgen(TX_S, TG_ON, NULL);
texgen(TX_T, TG_ON, NULL);
drawsgiobj(obj,DRAW_POINTS|DRAW_NORMALS);
texgen(TX_S, TG_OFF, NULL);
texgen(TX_T, TG_OFF, NULL);
} else {
shadeon();
setdiffuse(0.0,0.6,0.0);
setspecular(0.9,0.9,0.9);
lmcolor(LMC_DIFFUSE);
if(showmeshs)
drawsgiobjmeshs(obj);
else if(showcolors)
drawsgiobj(obj,DRAW_POINTS|DRAW_NORMALS|DRAW_COLORS);
else
drawsgiobj(obj,DRAW_POINTS|DRAW_NORMALS);
lmcolor(LMC_COLOR);
shadeoff();
}
}
if(shownormals) {
cpack(0x0000ff);
drawsgiobjnorms(obj);
}
}
mygfxinit()
{
zbuffer(1);
subpixel(1);
RGBmode();
doublebuffer();
gconfig();
cpack(0x808080);
clear();
swapbuffers();
fsetdepth(0.0,1.0);
}